﻿                                                                                                   

         
	using System;
    using System.Collections.Generic;
    using System.Data.Entity;
    using System.Linq;
    using System.Linq.Dynamic;
    using System.Text;
    using System.Threading.Tasks;
    using Abp;
    using Abp.Application.Services.Dto;
    using Abp.Authorization;
    using Abp.AutoMapper;
    using Abp.Configuration;
    using Abp.Domain.Repositories;
    using Abp.Extensions;
    using Abp.Linq.Extensions;
    using KDS.Mes.Mes.TestPower2s.Dtos;
using KDS.Mes.Dto;
using KDS.Mes.DataExporting.Excel.EpPlus;
using Abp.Timing.Timezone;
using Abp.Runtime.Session;

namespace KDS.Mes.Mes.TestPower2s
{
    /// <summary>
    /// 2线电检数据表的导出EXCEL功能的实现
    /// </summary>
    public class TestPower2ListExcelExporter : EpPlusExcelExporterBase, ITestPower2ListExcelExporter
    {
     
        private readonly ITimeZoneConverter _timeZoneConverter;
        private readonly IAbpSession _abpSession;


        /// <summary>
        /// 构造方法
        /// </summary>
        public TestPower2ListExcelExporter(ITimeZoneConverter timeZoneConverter,     IAbpSession abpSession)
        {
                       _timeZoneConverter = timeZoneConverter;    
                     _abpSession = abpSession;
        }

    

         /// <summary>
        /// 导出2线电检数据表到EXCEL文件
        /// <param name="testPower2ListDtos">导出信息的DTO</param>
        /// </summary>
    public    FileDto ExportTestPower2ToFile(List<TestPower2ListDto> testPower2ListDtos){


var file=CreateExcelPackage("testPower2List.xlsx",excelPackage=>{

var sheet=excelPackage.Workbook.Worksheets.Add(L("TestPower2"));
                    sheet.OutLineApplyStyle = true;

                    AddHeader(
                        sheet,
                          L("LINE"),  
     L("STATION_NO"),  
     L("SEAT_ID"),  
     L("RESULT"),  
     L("WARN_OFF_VAL"),  
     L("WARN_OFF_JUG"),  
     L("WARN_ON_VAL"),  
     L("WARN_ON_JUG"),  
     L("SAB_VAL"),  
     L("SAB_JUG"),  
     L("SBR_OFF_VAL"),  
     L("SBR_OFF_JUG"),  
     L("SBR_ON_VAL"),  
     L("SBR_ON_JUG"),  
     L("CREAT_TIME")  
                        );
         AddObjects(sheet,2,testPower2ListDtos,
            
      _ => _.LINE,   
       
      _ => _.STATION_NO,   
       
      _ => _.SEAT_ID,   
       
      _ => _.RESULT,   
       
      _ => _.WARN_OFF_VAL,   
       
      _ => _.WARN_OFF_JUG,   
       
      _ => _.WARN_ON_VAL,   
       
      _ => _.WARN_ON_JUG,   
       
      _ => _.SAB_VAL,   
       
      _ => _.SAB_JUG,   
       
      _ => _.SBR_OFF_VAL,   
       
      _ => _.SBR_OFF_JUG,   
       
      _ => _.SBR_ON_VAL,   
       
      _ => _.SBR_ON_JUG,   
       
 _ =>_timeZoneConverter.Convert( _.CREAT_TIME,_abpSession.TenantId, _abpSession.GetUserId())   
);
                    //写个时间转换的吧
          //var creationTimeColumn = sheet.Column(10);
                    //creationTimeColumn.Style.Numberformat.Format = "yyyy-mm-dd";

        for (var i = 1; i <= 15; i++)
                    {
                        sheet.Column(i).AutoFit();
                    }       

});
   return file;

}


 

 
  

    }
    }
